package com.xyf.testJPA.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.xyf.testJPA.bean.Teacher;
import com.xyf.testJPA.dao.TeacherDao;
import com.xyf.testJPA.service.ITeacherService;

@Service
public class TeacherServiceImpl implements ITeacherService{
	
	@Resource
	private TeacherDao teacherDao;
	
	public void saveTeacherBean(Teacher teacher) {
		System.out.println(teacherDao.save(teacher));
	}

	@Override
	public void saveBatch(List<Teacher> list) {
		// TODO Auto-generated method stub
		teacherDao.save(list);
		
	}

	@Override
	public void delTeacherBean(Teacher bean) {
		//两种都是按id删除对象,对象的id必须是包装类型
		teacherDao.delete(bean.getId());
//		teacherDao.delete(bean);
		//自己实现的删除
		teacherDao.deletebyid2(bean.getId());
		

	}

	@Override
	public void delBatch(List<Teacher> list) {
		// TODO Auto-generated method stub
		//两个都可以删除  但是两个方法来自于父子接口中
		teacherDao.delete(list);
//		teacherDao.deleteInBatch(list);
		
	}

	@Override
	public void delAll() {
		// TODO Auto-generated method stub
		teacherDao.deleteAll();
	}

	@Override
	public void updateTeacher(Teacher bean) {
		// TODO Auto-generated method stub
		teacherDao.saveAndFlush(bean);
	}

	@Override
	public Teacher findByID(Integer id) {
		// TODO Auto-generated method stub
		return teacherDao.findOne(id);
	}

	@Override
	public List<Teacher> findByIteam(Map iteam) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int findCountByIteam(Map iteam) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void updateTeacherSex(boolean sex, Integer id) {
		// TODO Auto-generated method stub
		teacherDao.updateTeacherSex(id, sex);
	}

	@Override
	public Teacher findOneByTeacherName(Teacher teacher) {
		// TODO Auto-generated method stub
		Example<Teacher> example = Example.of(teacher);  
		return teacherDao.findOne(example);
	}

	@Override
	public List<Teacher> findAll() {
		// TODO Auto-generated method stub
		return teacherDao.findAll();
	}
	
	

}
